--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_tenkyu_chimata = General:new(extension, "hy_tenkyu_chimata", "ten_k", 4, 4, General.Female)
    local expropriate = fk.CreateSkill {
        name = "expropriate",
    }
    expropriate:addEffect(fk.GameStart, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(expropriate.name)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player)
            local room = player.room
            for _, t in ipairs(room.alive_players) do
                if t == player then
                    local ids = room:askToCards(player, {
                        min_num = 1,
                        max_num = 1,
                        skill_name = expropriate.name,
                        cancelable = false,
                        prompt = "expropriate_prompt"
                    })
                    if type(ids) == "number" then
                        ids = { ids }
                    end
                    room:setPlayerMark(player, "@expropriate", Fk:getCardById(ids[1], true):toLogString())
                    player:addToPile("#expropriate", ids[1], true, expropriate.name)
                elseif #t:getCardIds("h") > 0 then
                    local id = room:askToChooseCard(player, {
                        target = t,
                        flag = "h",
                        skill_name = expropriate.name,
                        prompt = "expropriate_prompt",
                    })
                    room:setPlayerMark(t, "@expropriate", Fk:getCardById(id, true):toLogString())
                    t:addToPile("#expropriate", id, true, expropriate.name)
                end
            end
        end,
    })
    expropriate:addEffect(fk.AfterCardsMove, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            local is_expropriate = false
            for _, move in ipairs(data) do
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "#expropriate" then
                        is_expropriate = true
                        break
                    end
                end
            end
            if not is_expropriate then
                return false
            end
            local expropriate_count = 0
            for _, t in ipairs(player.room.alive_players) do
                if #t:getPile("#expropriate") > 0 then
                    expropriate_count = expropriate_count + 1
                end
            end
            return expropriate_count < 4 and player:hasSkill(expropriate.name) and not player.dead
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player)
            local room = player.room
            local moves = {}
            for _, t in ipairs(room.alive_players) do
                if #t:getPile("#expropriate") > 0 then
                    table.insertIfNeed(moves, {
                        ids = t:getPile("#expropriate"),
                        toArea = Card.PlayerHand,
                        to = player,
                        fromArea = Card.PlayerSpecial,
                        from = t,
                        moveReason = fk.ReasonPrey,
                        proposer = player,
                        skillName = expropriate.name,
                        specialName = "#expropriate",
                        specialVisible = true,
                        moveVisible = true,
                    })
                end
            end
            room:moveCards(table.unpack(moves))
            room:handleAddLoseSkills(player, "god_dominion|-trade", nil, true, false)
        end,
        can_refresh = function(self, event, target, player, data)
            for _, move in ipairs(data) do
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "#expropriate" and move.from == player then
                        return true
                    end
                end
            end
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:setPlayerMark(player, "@expropriate", 0)
        end
    })
    expropriate:addEffect(fk.EventPhaseStart, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            local expropriate_count = 0
            for _, t in ipairs(player.room.alive_players) do
                if #t:getPile("#expropriate") > 0 then
                    expropriate_count = expropriate_count + 1
                end
            end
            return expropriate_count < 4 and expropriate_count > 0 and player:hasSkill(expropriate.name) and not player.dead and player == target and player.phase == Player.Start
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player)
            local room = player.room
            local moves = {}
            for _, t in ipairs(room.alive_players) do
                if #t:getPile("#expropriate") > 0 then
                    table.insertIfNeed(moves, {
                        ids = t:getPile("#expropriate"),
                        toArea = Card.PlayerHand,
                        to = player,
                        fromArea = Card.PlayerSpecial,
                        from = t,
                        moveReason = fk.ReasonPrey,
                        proposer = player,
                        skillName = expropriate.name,
                        specialName = "#expropriate",
                        specialVisible = true,
                        moveVisible = true,
                    })
                end
            end
            room:moveCards(table.unpack(moves))
            room:handleAddLoseSkills(player, "god_dominion|-trade", nil, true, false)
        end,
    })
    expropriate:addEffect(fk.Death, {
        can_refresh = function(self, event, target, player)
            return target == player and (#player:getPile("#expropriate") > 0 or player:hasSkill(expropriate.name, true, true))
        end,
        on_refresh = function(self, event, target, player)
            local room = player.room
            local moves = {}
            table.insertIfNeed(moves, {
                ids = player:getPile("#expropriate"),
                toArea = Card.DiscardPile,
                fromArea = Card.PlayerSpecial,
                from = player,
                moveReason = fk.ReasonPutIntoDiscardPile,
                skillName = "expropriate",
                specialName = "#expropriate",
                specialVisible = true,
                moveVisible = true,
            })
            if player:hasSkill("expropriate", true, true) then
                for _, t in ipairs(table.filter(room.alive_players, function(t)
                    return #t:getPile("#expropriate") > 0
                end)) do
                    table.insertIfNeed(moves, {
                        ids = t:getPile("#expropriate"),
                        toArea = Card.DiscardPile,
                        fromArea = Card.PlayerSpecial,
                        from = t,
                        moveReason = fk.ReasonPutIntoDiscardPile,
                        skillName = "expropriate",
                        specialName = "#expropriate",
                        specialVisible = true,
                        moveVisible = true,
                    })
                end
            end
            room:moveCards(table.unpack(moves))
        end,
    })
    local trade = fk.CreateSkill {
        name = "trade",
    }
    trade:addEffect("active", {
        anim_type = "control",
        card_filter = Util.FalseFunc,
        target_num = 2,
        target_filter = function(self, player, to_select, selected, selected_cards)
            return #selected < 2 and #to_select:getPile("#expropriate") > 0 and not to_select:isKongcheng()
        end,
        can_use = function(self, player)
            return player:usedSkillTimes(trade.name, Player.HistoryPhase) == 0
        end,
        prompt = function(self, selected, selected_cards)
            return "trade_prompt"
        end,
        on_use = function(self, room, skillUseEvent)
            local player = skillUseEvent.from
            local target1 = skillUseEvent.tos[1]
            local target2 = skillUseEvent.tos[2]
            local result = target1:pindian({ target2 }, trade.name)
            if result.results[target2].winner == target1 then
                if not target1.dead then
                    room:drawCards(target1, 1, trade.name)
                end
                if not player.dead then
                    room:drawCards(player, 1, trade.name)
                end
                room:moveCards({
                    ids = target2:getPile("#expropriate"),
                    from = target2,
                    toArea = Card.PlayerHand,
                    to = player,
                    moveReason = fk.ReasonGive,
                    proposer = target2,
                    skillName = trade.name,
                })
            elseif result.results[target2].winner == target2 then
                if not target2.dead then
                    room:drawCards(target2, 1, trade.name)
                end
                if not player.dead then
                    room:drawCards(player, 1, trade.name)
                end
                room:moveCards({
                    ids = target1:getPile("#expropriate"),
                    from = target1,
                    toArea = Card.PlayerHand,
                    to = player,
                    moveReason = fk.ReasonGive,
                    proposer = target1,
                    skillName = trade.name,
                })
            else
                room:moveCards({
                    ids = target1:getPile("#expropriate"),
                    from = target1,
                    toArea = Card.PlayerHand,
                    to = player,
                    moveReason = fk.ReasonGive,
                    proposer = target1,
                    skillName = trade.name,
                })
                room:moveCards({
                    ids = target2:getPile("#expropriate"),
                    from = target2,
                    toArea = Card.PlayerHand,
                    to = player,
                    moveReason = fk.ReasonGive,
                    proposer = target2,
                    skillName = trade.name,
                })
            end
        end
    })
    local god_dominion = fk.CreateSkill {
        name = "god_dominion",
    }
    god_dominion:addEffect(fk.Damage, {
        times = function(self, player)
            return 2 - player:usedSkillTimes(god_dominion.name, Player.HistoryRound)
        end,
        can_trigger = function(self, event, target, player)
            return player:hasSkill(god_dominion.name) and target == player and player:usedSkillTimes(god_dominion.name, Player.HistoryRound) < 2 and not player.dead
        end,
        on_cost = function(self, event, target, player)
            local value = tostring(#player.room.alive_players)
            return player.room:askToSkillInvoke(player, {
                skill_name = god_dominion.name,
                prompt = "god_dominion_prompt:::" .. value .. ":" .. value
            })
        end,
        on_use = function(self, event, target, player)
            local room = player.room
            local count = #room.alive_players
            room:drawCards(player, count, god_dominion.name)
            local cards = table.filter(player:getCardIds("he"), function(id)
                return not player:prohibitDiscard(Fk:getCardById(id))
            end)
            if #cards >= count then
                room:askToDiscard(player, {
                    min_num = count,
                    max_num = count,
                    include_equip = true,
                    skill_name = god_dominion.name,
                    cancelable = false
                })
            elseif #cards > 0 then
                room:throwCard(cards, god_dominion.name, player, player)
            end
        end
    })
    god_dominion:addEffect("maxcards", {
        correct_func = function(self, player)
            if player:hasSkill(god_dominion.name) then
                return #Fk:currentRoom().alive_players
            end
        end
    })
    local lunatic_rainbow = fk.CreateSkill {
        name = "lunatic_rainbow",
        tags = {
            Skill.Lord
        }
    }
    lunatic_rainbow:addEffect(fk.Damage, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(lunatic_rainbow.name) and target and player:inMyAttackRange(target) and target.kingdom == "ten_k" and
                player:usedSkillTimes(lunatic_rainbow.name, Player.HistoryRound) < 1
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            if player:hasSkill("trade") and #table.filter(room.alive_players, function(t)
                    return #t:getPile("#expropriate") > 0
                end) >= 2 and player:hasSkill("god_dominion") and player:usedSkillTimes("god_dominion", Player.HistoryRound) < 2 then
                event:setCostData(self, room:askToChoice(target, {
                    choices = { "trade", "god_dominion", "Cancel" },
                    skill_name = lunatic_rainbow.name,
                    prompt = "lunatic_rainbow_prompt_both"
                }))
            elseif player:hasSkill("trade") and #table.filter(room.alive_players, function(t)
                    return #t:getPile("#expropriate") > 0
                end) >= 2 then
                event:setCostData(self, room:askToSkillInvoke(target, {
                    skill_name = god_dominion.name,
                    prompt = "lunatic_rainbow_prompt_trade"
                }) and "trade" or "Cancel")
            elseif player:hasSkill("god_dominion") and player:usedSkillTimes("god_dominion", Player.HistoryRound) < 2 then
                event:setCostData(self, room:askToSkillInvoke(target, {
                    skill_name = god_dominion.name,
                    prompt = "lunatic_rainbow_prompt_god_dominion"
                }) and "god_dominion" or "Cancel")
            else
                event:setCostData(self, "Cancel")
            end
            return event:getCostData(self) ~= "Cancel"
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if event:getCostData(self) == "trade" then
                room:askToUseActiveSkill(player, {
                    skill_name = "trade",
                    prompt = "trade_prompt",
                    cancelable = false,
                })
            elseif event:getCostData(self) == "god_dominion" then
                room:useSkill(player, Fk.skills["god_dominion"], function()
                    for _, sk in pairs(god_dominion.effects) do
                        if sk:isInstanceOf(TriggerSkill) then
                            ---@cast sk TriggerSkill
                            sk:use(fk.Damage, player, player)
                        end
                    end
                end)
            end
        end,
    })
    extension:loadSkillSkels { expropriate, trade, lunatic_rainbow, god_dominion }
    hy_tenkyu_chimata:addSkills { "expropriate", "trade", "lunatic_rainbow" }
    hy_tenkyu_chimata:addRelatedSkill("god_dominion")
    Fk:loadTranslationTable {
        ["hy_tenkyu_chimata"] = "天弓千亦",
        ["#hy_tenkyu_chimata"] = "独身复苏之神",
        ["illustrator:hy_tenkyu_chimata"] = "めいど",
        ["designer:hy_tenkyu_chimata"] = "黑曜人形",
        ["cv:hy_tenkyu_chimata"] = "",

        ["expropriate"] = "夺权",
        [":expropriate"] = "游戏开始时，你将所有角色各一张手牌移出游戏。准备阶段或一名角色移去“夺权”牌后，若有“夺权”牌的角色数小于4，你获得所有“夺权”牌，失去“交易”并获得“<a href = ':god_dominion'>神权</a>”。",
        ["@expropriate"] = "夺权",
        ["expropriate_prompt"] = "夺权：将一张手牌置于身份牌上",
        ["#expropriate"] = "夺权",

        ["trade"] = "交易",
        [":trade"] = "出牌阶段限一次，你可以令两名有“夺权”牌的角色拼点：赢的角色与你摸一张牌；没赢的角色将“夺权”牌交给你。",
        ["trade_prompt"] = "交易：令两名有“夺权”牌的角色拼点",

        ["lunatic_rainbow"] = "月虹",
        [":lunatic_rainbow"] = "主公技，每轮限一次，你攻击范围内的天势力角色造成伤害后，其可以令你发动一次“交易”或“神权”。",
        ["lunatic_rainbow_prompt_both"] = "月虹：你可以令主公发动其中一个技能",
        ["lunatic_rainbow_prompt_trade"] = "月虹：你可以令主公发动“交易”",
        ["lunatic_rainbow_prompt_god_dominion"] = "月虹：你可以令主公发动“神权”",

        ["god_dominion"] = "神权",
        [":god_dominion"] = "每轮限两次，在你造成伤害后，你可以摸X张牌并弃置X张牌。你的手牌上限+X（X为存活角色数）。",
        ["god_dominion_prompt"] = "神权：摸%arg张牌并弃置%arg2张牌",
    }
end
